// 入驻申请
<template>
   <div class="search">
     <Row>
        <Card>
          <Row class="operation">
            <Form inline :label-width="160" ref="searchForm" :model="searchForm" label-position="right">
              <Button @click="add" icon="md-add" type="primary">添加</Button>
              <Button @click="handleSearch" icon="md-refresh">刷新</Button>
              <FormItem label="审核状态" prop="checkStatus">
                <Select v-model="searchForm.checkStatus" style="width:200%" clearable>
                  <Option value="PRE_CHECK">待审核</Option>
                  <Option value="CHECK_SUCCESS">审核成功</Option>
                  <Option value="CHECK_FAIL">审核失败</Option>
                </Select>
              </FormItem>
              <Button @click="handleSearch" type="primary" icon="ios-search" style="margin-left:100px;">搜索</Button>
            </Form>
          </Row>
          <Modal title="查看大图" v-model="visible" class-name="fl-image-modal">
            <img :src="imgUrl" v-if="visible" style="width: 100%">
          </Modal>

          <Row>
            <Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort"></Table>
          </Row>

          <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
          </Row>
        </Card>
     </Row>

     <Modal :title="modalTitle" v-model="modalVisible" :mask-closable='false' :width="600">
      <Form ref="form" :model="form" :label-width="100" :rules="formValidate" >
        <FormItem label="标签名称" prop="firstRateServiceIds">
          <Select v-model="form.firstRateServiceIds" style="width: 100%" clearable>
            <Option :value="item.id" v-for="item in serviceData" :key="item.id">{{item.itemName}}</Option>
          </Select> 
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="commentVisible=false">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="handleSubmit">提交</Button>
      </div>
    </Modal>
   </div> 
</template>

<script>
export default {
  data(){
    return{ 
      submitLoading: false,
      visible:false,
      detailVisible: false,
      total:0,
      modalTitle: "",
      loading: true, // 表单加载状态
      data:[],//表单数据
      searchForm:{
        checkStatus:"",
        pageSize:10,
        pageNumber:1,
      },
      form: {
        firstRateServiceIds: "",
      },
      modalVisible: false,
      formValidate: {
        firstRateServiceIds: [{ required: true, message: "请选择优质服务", trigger: "change" }],
      },
      columns: [
      // 表头
      {
        type: "index",
        width: 60,
        align: "center"
      },
      {
        title: "标签名称",
        key: "itemName",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "审核状态",
        key: "checkStatus",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "审核原因",
        key: "checkReason",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "创建时间",
        key: "createTime",
        minWidth: 120,
        sortable: false,
      },
      ],
      serviceData: [],
      }
    },
    methods:{
      init(){
        this.getDataList();
        this.getServiceList();
      },
      handleView(url) {
        this.imgUrl = url;
        this.visible = true;
      },
      getServiceList () {
        var data = {
            pageNumber: 1,
            pageSize: 1000
        }
        this.postRequest("/firstRateService/getFirstRateService", data).then(res=> {
          if (res.success) {
            this.serviceData = res.result.data
          } else {
            this.serviceData = []
          }
        })
      },
      getDataList(){
        (this.searchForm.checkStatus == undefined) ? (this.searchForm.checkStatus = "") : ""
        this.loading = true;
        this.postRequest("/storeFirstRateService/getStoreFirstRateService",this.searchForm).then(res =>{
            this.loading = false
            if(res.success){
                var arr = res.result.data;
                for(let val of arr){
                  for(let i in val){
                    (val[i] === null) ? (val[i] = "-") : ""
                  }
                }
                this.data = arr;
                this.total = res.result.size;
            } else {
                this.data = [];
                this.total = 0;
            }
        })
      },
      //搜索查询
      handleSearch(){
        this.searchForm.pageNumber = 1;
        this.getDataList()
      },
      changeSort(e) {
        this.searchForm.sort = e.key;
        this.searchForm.order = e.order;
        if (e.order === "normal") {
          this.searchForm.order = "";
        }
        this.getDataList();
      },
      changePage(v) {
        this.searchForm.pageNumber = v;
        this.getDataList();
      },
      changePageSize(v) {
        this.searchForm.pageSize = v;
        this.getDataList();
      },
      clearSelectAll(){
        this.$refs.searchForm.resetFields()
        this.getDataList()
      },
      add (v) {
        this.$refs.form.resetFields();
        this.modalTitle = "添加";
        this.modalType = 0;
        this.modalVisible = true;
      },
      handleSubmit () {
        this.$refs.form.validate(valid=> {
          if (valid) {
            this.submitLoading = true;
            if (this.modalType === 0) {
              delete this.form.id;
              this.postRequest("/storeFirstRateService/insertOrderUpdateStoreFirstRateService", this.form).then(res=> {
                this.submitLoading = false;
                if (res.success) {
                  this.$Message.success("申请成功");
                  this.getDataList();
                  this.modalVisible = false;
                } else {
                  this.$Message.error(res.message);
                  this.modalVisible = false;
                }
              })
            }
          }
        })
      },
    },
    mounted(){
      this.init()
    }
}
</script>

<style lang="less">
.search {
    .operation {
        margin-bottom: 2vh;
    }
    .select-count {
        font-size: 13px;
        font-weight: 600;  
        color: #40a9ff;
    }
    .select-clear {
        margin-left: 10px;
    }
    .page {
        margin-top: 2vh;
    }
    .drop-down {
        font-size: 13px;
        margin-left: 5px;
    }
}
</style>z